package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"zg4day5_zy/model/mysql"
	"zg4day5_zy/rouquest"
)

func Video(c *gin.Context) {
	var App rouquest.GetCreate
	if err := c.ShouldBind(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := mysql.Video{
		VideoTitle:        App.VideoTitle,
		VideoTitleDetails: App.VideoTitleDetails,
		VideoAvatar:       App.VideoAvatar,
		VideoAddress:      App.VideoAddress,
		VideoStatus:       App.VideoStatus,
		VideoSort:         App.VideoSort,
	}
	err := stu.Create()
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": "添加失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"msg": "添加成功"})
}
func VideoList(c *gin.Context) {
	var App rouquest.VideoList
	if err := c.ShouldBind(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := mysql.Video{}
	res, err := stu.List(App.Keyword, App.Page, App.PageSize)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": "查询失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"msg": "查询成功", "res": res})
}
